package main.nk.mygraph;

import javafx.application.Application;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

/**
 * 练习布局的高宽属性的动态获取
 */

public class Test5 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {



        final Stage stage = primaryStage;
        final Pane pane = new Pane();

        ReadOnlyDoubleProperty width = pane.widthProperty();

        width.addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                System.out.println("宽度：" + newValue);
            }
        });

        ReadOnlyDoubleProperty height = pane.heightProperty();
        height.addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                System.out.println("高度" + newValue);
                if(newValue.intValue() ==  700){
                    System.out.println("高度不能在高了");
                    pane.getChildren().add(new Label("hahah"));

                }
            }
        });

        Scene scene = new Scene(pane);
        primaryStage.setTitle("高宽的属性获取");
        primaryStage.setScene(scene);
        primaryStage.show();

    }


}
